﻿using System;
using System.Collections.Generic;

namespace Zsnd.Helpers {
    public static class StringHelpers {
        public static IList<int> ToIntList(this String id) {
            string[] sid = id.Split(',');
            List<int> l = new List<int>();
            foreach (string s in sid) {
                int result;
                if (int.TryParse(s, out result)) {
                    l.Add(result);
                }
            }
            return l;
        }

        public static IList<double> ToDouList(this String id) {
            string[] sid = id.Split(',');
            List<double> l = new List<double>();
            foreach (string s in sid) {
                double result;
                if (double.TryParse(s, out result)) {
                    l.Add(result);
                }
            }
            return l;
        }

        public static IList<decimal> ToDecList(this String id) {
            string[] sid = id.Split(',');
            List<decimal> l = new List<decimal>();
            foreach (string s in sid) {
                decimal result;
                if (decimal.TryParse(s, out result)) {
                    l.Add(result);
                }
            }
            return l;
        }

        public static string ToDate(this DateTime? date) {
            if (date == null) return null;
            return ((DateTime)date).ToString("yyyy-MM-dd");
        }
        public static string ToDate(this DateTime date) {
            return date.ToString("yyyy-MM-dd");
        }
    }
}